package com.joven.product.service.business.domain.model.entity.id;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.UUID;

/**
 * 领域对象委派id
 *
 * @author Joven
 * @date 2022-01-06 18:21:27
 */
@Data
@SuperBuilder
@NoArgsConstructor
public class DomainObjId {
    /**
     * 预生成唯一id
     */
    private final String preId = UUID.randomUUID().toString();

    /**
     * id值
     */
    private Long value;

    /**
     * 状态
     */
    private EntityStatus status;

    public DomainObjId(Long value) {
        this.value = value;
        this.status = EntityStatus.UNCHANGED;
    }

    public DomainObjId(Long value, EntityStatus status) {
        this.value = value;
        this.status = status;
        if (status == null) {
            throw new IllegalArgumentException("DomainObjId's status cannot be null");
        }
    }

    public DomainObjId(EntityStatus status) {
        if (status == null) {
            throw new IllegalArgumentException("DomainObjId's status cannot be null");
        }
        this.status = status;
    }

}
